//
//  MovieListCell.m
//  UI_豆瓣2.0
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieListCell.h"
#import "UIImageView+WebCache.h"
#import "MovieList.h"
@interface MovieListCell ()

@property (nonatomic, retain)UIImageView *backGroundImageView; // 背景图片
@property (nonatomic, retain)UIImageView *pictureImageView;   // 图片
@property (nonatomic, retain)UILabel *movieNameLabel;// 电影名
@property (nonatomic, retain)MovieList *movie;

@property(nonatomic,retain)UIButton *button;
@end

@implementation MovieListCell

- (void)dealloc
{
    [_movieLCell release];
    [_backGroundImageView release];
    [_pictureImageView release];
    [_movieNameLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
// 背景
    self.backGroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, HEIGHT - 532)];
    self.backGroundImageView.image = [UIImage imageNamed:@"bg_eventlistcell.png"];
    [self.contentView addSubview:self.backGroundImageView];
    [_backGroundImageView release];
    
// 照片
    self.pictureImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 14, WIDTH - 290, HEIGHT - 542)];
    self.pictureImageView.image = [UIImage imageNamed:@"picholder.png"];
    [self.contentView addSubview:self.pictureImageView];
    [_pictureImageView release];
// 电影名
    self.movieNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(125, 50, WIDTH - 175, HEIGHT - 627)];
    self.movieNameLabel.font = [UIFont systemFontOfSize:20];
    self.movieNameLabel.text = @"帅帅";
    [self.contentView addSubview:self.movieNameLabel];
    [_movieNameLabel release];
    

    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(330, 10, 24, 24);
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];


}






-(void)buttonAction:(UIButton *)button
{
    
    if (self.movie.isSelected) {
        
        //2.点击按钮的时候加判断
        [self.button setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    }
    
    self.movie.isSelected = !self.movie.isSelected;
    
    
}


#pragma mark -- 重写setter方法
-(void)setMovieLCell:(MovieList *)movieLCell{
    if (_movieLCell != movieLCell) {
        [_movieLCell release];
        _movieLCell = [movieLCell retain];
    }
    self.movieNameLabel.text = self.movieLCell.movieName;
    [self.pictureImageView  sd_setImageWithURL:[NSURL URLWithString:self.movieLCell.pic_url] placeholderImage:[UIImage imageNamed:@"picholder.png"]];
    
    [self.button setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    
    if (_movieLCell.isSelected) {
        
        [self.button setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    }

}











- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
